import echarts from 'echarts';
// 折线图
export function getRDchart(title, Dates, ListData) {
    let series = [];
    let legendData = [];
    ListData.map((items) => {
        legendData.push(items.name)
    })
    ListData.map((item) => {
        series.push({
            name: item.name,
            type: 'line',
            smooth: true,
            itemStyle: { normal: { areaStyle: { type: 'default' } } },
            data: item.data,
        })
    });

    let option = {
        color: ['#2de5f0', '#ffd200', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'],
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: legendData
        },
        grid: {
            // left: '5%'
            right: '1%',
            height: '60%',
            y: '15%',
        },
        calculable: true,
        xAxis: [{
            type: 'category',
            boundaryGap: false,
            data: Dates,
            axisLabel: {
                interval: 1,
                rotate: 30,
                fontSize: 11,
            }
        }],
        yAxis: [{
            type: 'value'
        }],

        series: series
    }
    return option;
}

export function getBarOption(title, Dates, industry_data, own_data) {

    let option = {
        color: ['#D8A874', '#151415' ,'#ffd200', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'],
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['本期评分', '行业均值']
        },
        calculable: true,
        xAxis: [{
            type: 'category',
            data: Dates,
            axisLabel: {
                interval: 0,
                rotate: 30,
                fontSize: 11,
            }
        }],
        yAxis: [{
            type: 'value'
        }],
        series: [{
                name: '本期评分',
                type: 'bar',
                barWidth: '60%',
                data: own_data,
            },
            {
                name: '行业均值',
                type: 'line',
                data: industry_data
            },
        ]
    }
    return option;
}

export function getPiachart(title, datas) {
    // console.log("PiaData",datas)
    let d = [];
    for(let i=1;i<datas.length;i++){
       let e ={};
       e.name = datas[i].name;
       e.value = datas[i].count;
       d.push(e)
    }

    // console.log("d",d)

    let option = {
        color: ['#2de5f0', '#ffd200', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'],
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },

        grid: {
            height: '80%',
            y: '-5%',
        },

        calculable: true,
        series: [{
            name: '访问来源',
            type: 'pie',
            radius: ['50%', '70%'],
            itemStyle: {
                normal: {
                    label: {
                        show: true,
                        formatter: "{b}({d}%)"
                    },
                    labelLine: {
                        show: true
                    }
                },
                emphasis: {
                    label: {
                        show: true,
                        position: 'center',
                        textStyle: {
                            fontSize: '30',
                            fontWeight: 'bold'
                        }
                    }
                }
            },
            data: d
        }]
    }
    return option;
}
/**
 * 
 * @param {*} Dates 
 * @param {*} Datess 
 * @param {*} self 指标
 * @param {*} avg 行业均值
 * @param {*} income 营业收入
 * @param {*} profit 营业利润
 * @param {*} market 市值
 */
export function getFinancialOption(x, self, avg, income, profit, market) {
  // 找到最长日期
  // 指标
  // self.values = self.values.map((item) => {
  //   return (item * 100).toFixed(2);
  // })
  // 行业均值
  // avg.values = avg.values.map((item) => {
  //   return (item * 100).toFixed(2);
  // })
  // 营业收入
  income.values = income.values.map((item) => {
    //return Number(item.replace(/,/g, ''));
    return Number(item);
  })
   // 营业收入
  profit.values = profit.values.map((item) => {
    return Number(item);
  })
  // 市值
  market.values = market.values.map((item) => {
    return Number(item);
  })

  let option = {
      color: ['#61a0a8', '#d48265', '#88b3f5', '#ffd200', '#c4ccd3'],
      tooltip: {
          trigger: 'axis'
      },
      legend: {
          data: ['指标', '行业均值', '营业收入', '营业利润', '市值']
      },
      // calculable: true,
      grid: {
          y: '10%',
          height: '70%',
          bottom: 0,
      },
      xAxis: [ // self avg income profit market
        { // 0 指标
          type: 'category',
          data: x,
          axisLabel: {
              interval: 0,
              rotate: 30,
              fontSize: 10,
          }
      },    
      { // 1 市值
          type: 'category',
          data: market.x,
          show: false,
      },
    ],
      yAxis: [{
          type: 'value',
          axisLabel: {
              //formatter: `${value} * 100 %`
              formatter: '{value}'
          }
      }, {
          type: 'value',
          name: '市值(元)',
          axisLabel: {
              formatter: function(value,index){
                  let v = value / 100000000;
                  // console.log("市值",v)
                  return (v + "亿")
              }
          }
      }],

      series: [{
              name: '指标',
              type: 'line',
              data: self.values
          },
          {
              name: '行业均值',
              type: 'line',
              data: avg.values
          },
          {
              name: '营业收入',
              type: 'line',
              yAxisIndex: 1,
              data: income.values
          },
          {
              name: '营业利润',
              type: 'line',
              yAxisIndex: 1,
              data: profit.values
          },
          {
              name: '市值',
              type: 'bar',
              yAxisIndex: 1,
              xAxisIndex: 1,
              data: market.x.map((d, i) => [d, market.values[i]])
          },
      ]
  }
  return option;
}

export function getAllBarOption(title, Dates, Datess, own_data, industry_avg, operating_income, operating_profit, market_value_data) {
    let own = [];
    let avg = [];
    let income = [];
    let profit = [];
    let market = [];
    // let startNum = 0;
    // let endNum = 2;
    for (let j = 0; j < own_data.length; j++) {
        income.push(Number(operating_income[j].replace(/,/g, '')));
        profit.push(Number(operating_profit[j].replace(/,/g, '')));
        own.push((own_data[j] * 100).toFixed(2));
        avg.push((industry_avg[j] * 100).toFixed(2));
    }
    console.log("avg",avg)
    for (let i = 0; i < market_value_data.length; i++) {
        market.push(Number(market_value_data[i].replace(/,/g, '')))
    }
    let option = {
        color: ['#61a0a8', '#d48265', '#88b3f5', '#ffd200', '#c4ccd3'],
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['指标', '行业均值', '营业收入', '营业利润', '市值']
        },
        // calculable: true,
        grid: {
            y: '10%',
            height: '70%',
            bottom: 0,
        },
        xAxis: [
          { // 指标
            type: 'category',
            data: Datess,
            axisLabel: {
                interval: 0,
                rotate: 30,
                fontSize: 10,
            }
        }, { // 行业均值
            type: 'category',
            data: Dates,
            show: false,
        }],
        yAxis: [{
            type: 'value',
            axisLabel: {
                //formatter: `${value} * 100 %`
                formatter: '{value} %'
            }
        }, {
            type: 'value',
            name: '市值(元)',
            axisLabel: {
                formatter: function(value,index){
                    let v = value / 100000000;
                    // console.log("市值",v)
                    return (v + "亿")
                }
            }
        }],

        series: [{
                name: '指标',
                type: 'line',
                data: own
            },
            {
                name: '行业均值',
                type: 'line',
                data: avg
            },
            {
                name: '营业收入',
                type: 'line',
                yAxisIndex: 1,
                data: income
            },
            {
                name: '营业利润',
                type: 'line',
                yAxisIndex: 1,
                data: profit
            },
            {
                name: '市值',
                type: 'bar',
                yAxisIndex: 1,
                xAxisIndex: 1,
                data: Dates.map((x, i) => [x, market[i]])
            },
        ]
    }
    return option;
}

export function generateFirstChartOption(dates, data) {
    let option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        xAxis: [{
                type: 'category',
                data: dates,
                // axisLabel: {
                //     interval: 0,
                //     rotate: -40
                // },  
            },
            {
                show: false,
                type: 'category',
            },
        ],
        yAxis: [{
                type: 'value',
            },
            {
                type: 'value',
                splitLine: {
                    show: false
                },
            }
        ],
        series: [{
            type: 'line',
            data: data,
            smooth: false
        }],
    };
    return option;
}

export function getGrowAbilitiesOption(title, Dates, Datess, own_data, industry_avg, operating_income, operating_profit, market_value_data) {
    let own = [];
    let avg = [];
    let income = [];
    let profit = [];
    let market = [];
    // let startNum = 0;
    // let endNum = 2;
    for (let j = 0; j < own_data.length; j++) {
        income.push(Number(operating_income[j].replace(/,/g, '')));
        profit.push(Number(operating_profit[j].replace(/,/g, '')));
        own.push(own_data[j] / 10);
        avg.push(industry_avg[j] / 10)
    }
    for (let i = 0; i < market_value_data.length; i++) {
        market.push(Number(market_value_data[i].replace(/,/g, '')))
    }
    let option = {
        color: ['#61a0a8', '#d48265', '#88b3f5', '#ffd200', '#c4ccd3'],
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['指标', '行业均值', '营业收入', '营业利润', '市值']
        },
        // calculable: true,
        grid: {
            y: '10%',
            height: '70%',
            bottom: 0,
        },
        // dataZoom: {
        //     show: true,
        //     realtime: true,
        //     bottom: 0,
        //     start: startNum,
        //     end: endNum
        // },
        xAxis: [{
            type: 'category',
            data: Datess,
            axisLabel: {
                interval: 0,
                rotate: 30,
                fontSize: 10,
            }
        }, {
            type: 'category',
            data: Dates,
            show: false,
        }],
        yAxis: [{
            type: 'value',
            axisLabel: {
                //formatter: `${value} * 100 %`
                formatter: '{value} %'
            }
        }, {
            type: 'value',
            name: '市值(元)',
            axisLabel: {
                formatter: function(value,index){
                    let v = value / 100000000;
                    // console.log("市值",v)
                    return (v + "亿")
                }
            }
        }],

        series: [{
                name: '指标',
                type: 'line',
                data: own
            },
            {
                name: '行业均值',
                type: 'line',
                data: avg
            },
            {
                name: '营业收入',
                type: 'line',
                yAxisIndex: 1,
                data: income
            },
            {
                name: '营业利润',
                type: 'line',
                yAxisIndex: 1,
                data: profit
            },
            {
                name: '市值',
                type: 'bar',
                yAxisIndex: 1,
                xAxisIndex: 1,
                data: Dates.map((x, i) => [x, market[i]])
            },
        ]
    }
    return option;
}

export function getOperationCapacityOption(title, Dates, Datess, own_data, industry_avg, operating_income, operating_profit, market_value_data) {
    let own = [];
    let avg = [];
    let income = [];
    let profit = [];
    let market = [];
    // let startNum = 0;
    // let endNum = 2;
    for (let j = 0; j < own_data.length; j++) {
        income.push(Number(operating_income[j].replace(/,/g, '')));
        profit.push(Number(operating_profit[j].replace(/,/g, '')));
        own.push(own_data[j]);
        avg.push(industry_avg[j])
    }
    for (let i = 0; i < market_value_data.length; i++) {
        market.push(Number(market_value_data[i].replace(/,/g, '')))
    }
    // console.log("own", own)
        // console.log("market", market)
    let option = {
        color: ['#61a0a8', '#d48265', '#88b3f5', '#ffd200', '#c4ccd3'],
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['指标', '行业均值', '营业收入', '营业利润', '市值']
        },
        // calculable: true,
        grid: {
            y: '10%',
            height: '70%',
            bottom: 0,
        },
        // dataZoom: {
        //     show: true,
        //     realtime: true,
        //     bottom: 0,
        //     start: startNum,
        //     end: endNum
        // },
        xAxis: [{
            type: 'category',
            data: Datess,
            axisLabel: {
                interval: 0,
                rotate: 30,
                fontSize: 10,
            }
        }, {
            type: 'category',
            data: Dates,
            show: false,
        }],
        yAxis: [{
            type: 'value',
            axisLabel: {
                //formatter: `${value} * 100 %`
                formatter: '{value}'
            }
        }, {
            type: 'value',
            name: '市值(元)',
            axisLabel: {
                formatter: function(value,index){
                    let v = value / 100000000;
                    // console.log("市值",v)
                    return (v + "亿")
                }
            }
        }],

        series: [{
                name: '指标',
                type: 'line',
                data: own
            },
            {
                name: '行业均值',
                type: 'line',
                data: avg
            },
            {
                name: '营业收入',
                type: 'line',
                yAxisIndex: 1,
                data: income
            },
            {
                name: '营业利润',
                type: 'line',
                yAxisIndex: 1,
                data: profit
            },
            {
                name: '市值',
                type: 'bar',
                yAxisIndex: 1,
                xAxisIndex: 1,
                data: Dates.map((x, i) => [x, market[i]])
            },
        ]
    }
    return option;
}


export function generateScoreChartOption(title, name, header, data) {
    // console.log(data)
    let option = {

        baseOption: {
            title: {
                text: title,
                x: 'center',
            },
            tooltip: {
                show: true,
                trigger: 'axis'
            },
            timeline: {
                show: true,
                axisType: 'category',
                autoPlay: false,
                y: '90%',
                data: header,
            },
            toolbox: {
                show: true,
                orient: 'horizontal',
                x: '50%',
                y: '95%',
            },
            xAxis: {
                type: 'category',
                // axisLabel: {
                //     interval: 0,
                //     show: true,
                //     rotate:80
                // }
            },
            yAxis: {
                type: 'value',
                name: '得分',
                nameLocation: 'middle',
                nameGap: 30,
            },
            grid: {
                height: '65%',
            },
            legend: {
                show: true,
                orient: 'horizontal',
                x: '80%',
                y: '10%'
            },
            dataZoom: [
                {
                    y: '73%',
                    type: 'slider',
                    xAxisIndex: [0],
                    filterMode: 'filter'
                }
            ],
        },
        options: data.map((a) => {
            return {
                legend: {
                    data: a[0].slice(1)
                },
                dataset: {
                    source: a,
                },
                series: constructSeries(a, "line")
            };
        })
    };
    return option;
}

export function generateRadarChartOption(title, name, data) {
    let option = {
        baseOption: {
            title: {
                text: title,
                x: 'center',
            },
            tooltip: {},
            timeline: {
                show: true,
                axisType: 'category',
                autoPlay: false,
                data: ['按年数据99%置信度', '按年数据95%置信度', '按报告期99%置信度', '按报告期95%置信度']
            },
            legend: {
                x: '80%',
                orient: 'vertical',
            },
            radar: {
                name: {
                    textStyle: {
                        color: '#000000',
                    }
                },
            },
        },
        options: data.map(function(a) {
            return {
                legend: {
                    data: a["dates"],
                },
                radar: {
                    indicator: a["indicator"]
                },
                series: [{
                    type: 'radar',
                    data : a["scores"],
                    emphasis: {
                        areaStyle: {
                            color: 'rgba(234,134,119,0.7)'
                        }
                    }
                }]
            };
        }),
    };
    return option;
}

export function generateItemChartOption(title, name, dates, data) {
    let option = {
        baseOption: {
            title: {
                text: title,
                x: 'center',
                y: '0'
            },
            tooltip: {
                show: true,
                formatter: "{a} <br/>{c}"
            },
            timeline: {
                show: true,
                axisType: 'category',
                autoPlay: false,
                y: '90%',
                label: {
                    interval: 0,
                    show: true,
                },
                tooltip: {
                    formatter: "{b}",
                },
                data: ['按项目偏离(调整后)', '按项目波动(调整后)', '按项目偏离', '按项目波动', '以上全部科目']
            },
            toolbox: {
                show: true,
                orient: 'horizontal',
                x: '50%',
                y: '95%',
            },
            xAxis: {
                type: 'category',
                data: dates,
                axisLabel: {
                    show: true,
                    interval: 0,
                    rotate: 20,
                    showMinLabel: true,
                }
            },
            yAxis: {
                type: 'value',
                axisLabel: {
                    formatter: function(value, index) {
                        return parseFloat(value).toFixed(1) / 100000000 + '亿';
                    }
                }
            },
            legend: {
                show: true,
                orient: 'horizontal',
                y: '8%'
            },
            grid: {
                y: '23%',
                height: '60%'
            },
            dataZoom: [
                {
                    y: '80%',
                    type: 'slider',
                    xAxisIndex: [0],
                    filterMode: 'filter'
                }
            ],
        },
        options: data,
    };
    return option;
}

export function generateZScoreChartOption(title, header, data) {
    let option = {
        title: {
            text: title,
            x: 'center',
        },
        tooltip: {
            trigger: 'axis'
        },
        xAxis: {
            type: 'category',
            data: header
        },
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [{
            data: data,
            type: 'line',
            markArea: {
                data: [
                    [{
                        name: '破产区',
                        label: {
                            position: 'inside'
                        },
                        emphasis: {
                            label: {
                                position: 'inside'
                            },
                        },
                        itemStyle: {
                            color: "rgba(208, 110, 107, 0.5)"
                        },
                        yAxis: 0
                    }, {
                        yAxis: 1.81
                    }],
                    [{
                        name: '灰色区',
                        label: {
                            position: 'inside'
                        },
                        emphasis: {
                            label: {
                                position: 'inside'
                            },
                        },
                        itemStyle: {
                            color: "rgba(227, 164, 144, 0.5)"
                        },
                        yAxis: 1.81
                    }, {
                        yAxis: 2.675
                    }],
                    [{
                        name: '安全区\n',
                        label: {
                            position: 'inside'
                        },
                        emphasis: {
                            label: {
                                position: 'inside'
                            },
                        },
                        itemStyle: {
                            color: "rgba(174, 212, 194, 0.5)"
                        },
                        yAxis: 2.675
                    }, {
                        yAxis: 100
                    }]
                ]
            }
        }]
    };
    return option;
}

export function generateClusterVisOption(title, list_of_clusters, header, data, thisStockName) {
    let option = {
        baseOption: {
            title: {
                text: title,
                x: 'center',
            },
            tooltip: {
                show: false,
            },
            timeline: {
                show: true,
                axisType: 'category',
                autoPlay: false,
                y: '90%',
                data: list_of_clusters.map(function(a) {
                    return "分" + a + "类";
                })
            },
            edgeLabel: {
                show: false,
            }
        },
        options: formOptionsOfGraph(header, data, thisStockName),
    };
    return option;
}

function formOptionsOfGraph(header, clusterData, thisStockName) {
    let options = []
    for (let key in clusterData) {
        let numClusters = parseInt(key);
        let categories = []
        for (let i = 0; i < numClusters; i++) {
            categories.push({ name: "类目 " + i })
        }
        let node_set = header[key].map(function(a) {
            let textColor = 'white';
            if (a[0] == thisStockName) {
                textColor = 'red';
            }
            return {
                id: a[0],
                label: {
                    textStyle: {
                        color: textColor
                    },
                    textBorderColor: 'auto',
                    textBorderWidth: 2,
                },
                symbolSize: 10,
                name: a[0],
                category: "类目 " + a[1],
            }
        });
        let option = {
            // legend: [{
            //     data: categories.map(function(a) {
            //         return a.name;
            //     })
            // }],
            series: [{
                name: key,
                label: {
                    normal: {
                        show: true
                    }
                },
                force: {
                    repulsion: 30,
                    layoutAnimation: false,
                },
                type: 'graph',
                layout: 'force',
                roam: true,
                data: node_set,
                edges: clusterData[key].map(function(a) {
                    return {
                        source: a[0],
                        target: a[1]
                    }
                }),
                categories: categories,
            }],
        };
        options.push(option);
    }
    return options;
}

export function generateTraditionalChartOption(title, headers, dates, values) {
    let option = {
        title: {
            text: title,
            x: 'center',
        },
        tooltip: {},
        legend: {
            x: '83%',
            y: 'center',
			orient: 'vertical',
			data: dates,
        },
		radar: {
			name: {
				textStyle: {
					color: '#000000',
				}
			},
			indicator: headers.map(function(a) {
				return {
					name: a,
					max: 100
				}
			}),
		},
		series: [{
		    type: 'radar',
            data : values,
            emphasis: {
                areaStyle: {
                    color: 'rgba(234,134,119,0.7)'
                }
            }
        }]
    };
    return option;
}

export function generateStackBarOption(title, dates, headers, legends, values) {
    let opts = []
    for (let i = 0; i < dates.length; i++) {
        opts.push({
            xAxis: {
                data: headers[i],
            },
            series: values[i],
            legend: {
                data: legends[i],
            }
        });
    }
    let option = {
        baseOption: {
            title: {
                text: title,
                x: 'center',
            },
            legend: {
                y: "5%"
            },
            xAxis: {
                name: "变动科目",
                type: 'category',
                axisLabel: {
                    rotate: 60,
                },
                axisTick: {
                    alignWithLabel: true,
                }
            },
            yAxis: {
                name: "特征变动方向",
                axisLabel: { show: false },
            },
            grid: {
                top: '20%',
                right: '15%',
                left: 100,
            },
            tooltip: {
                formatter: (params) => {
                    return params.name + " 相对于 " + params.seriesName.replace(/\s/g, '') + "<br />特征值: " + (params.data > 0 ? "异常增高" : "异常降低");
                },
            },
            timeline: {
                show: true,
                axisType: 'category',
                autoPlay: false,
                orient: 'vertical',
                left: '92%',
                right: '8%',
                top: '20%',
                bottom: '10%',
                data: dates,
                label: {
                    position: 10,
                }
            },
        },
        options: opts,
    };
    // console.log(option);
    return option;
}

export function generateLineChartOption(title, headers, values) {
    let option = {
        title: {
            text: title,
            x: 'center',
        },
        tooltip: {
            trigger: 'axis'
        },
        grid: {
            height: '70%',
        },
        legend:{
            x: '70%',
            y: '1%'
        },
        xAxis: [
            {
                name: "报告期",
                type: 'category',
                data: headers,
                nameGap: 10,
                axisTick: {
                    alignWithLabel: true,
                }
            },
                {
                    type: 'category',
                }
            
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        dataZoom: [
            {
                y: '80%',
                type: 'slider',
                xAxisIndex: [0],
                filterMode: 'filter'
            }
        ],
        series: [{
            name:'',
            type: 'line',
            data : values.map((a)=>{
                return a===0?'-':a;
            }),
        }]
    };
    return option;
}

export function generateSunburstChartOption(title, data, layer) {
    console.log("generateSunburst",data)
    let levels = [
        {},
        {
            r0: '0',
            r: '12%',
            itemStyle: {
                borderWidth: 1
            },
            label: {
                rotate: 'tangential',
                align:'center'
            }
        }
   ];
   let deg = 48/(layer);
   for(let i=0;i<layer;i++){
        levels.push({
            r0:12+deg*i + '%',
            r:12+deg*(i+1) + '%',
            label: {
                rotate: 'tangential',
                align:'center'
            }
        })
   }
   levels.push({
        r0: '60%',
        r: '62%',
        label: {
            color:'auto',
            shadowColor:'auto',
            // textBorderColor:'#000',
            position: 'outside',
        },
    })
    let option = {
        tooltip:{
            formatter: (params) => {
               return params.data.name;
            },
        },
        title: {
            text: title,
            x: 'center',
            subtextStyle: {
                align: 'center'
            }, 
        },
        series: {
            type: 'sunburst',
            highlightPolicy: 'self',
            data: data,
            radius: [0, '90%'],
            sort: null,
            center: ['50%','52%'],
            levels: levels,
        }
    }
    return option;
}

export function generateAbormalLineChartOption(title, dates, values) {
    let series = [],
        items = [];
    values.map((value)=>{
        if(value.name === '净利润'||value.name === '营业收入' || value==="总资产"){
            let data = [];
            value.itemVal.map(item=>{
                data.push(item/value.value);
            })
            series.push({
                name: value.name + '占比',
                type: 'line',
                data: data,
                smooth: true
            });
            items.push(value.name+ '占比');  
        }else{
            series.push({
                name: value.name,
                type: 'line',
                data: value.value,
                smooth: true
             });
             items.push(value.name);  
        }
         
    })
    let option = {
        title: {
            text: title,
            x: 'center',
        },
        tooltip: {},
        legend: {
            data: items,
            x: '80%',
            y: '10%'
        },
        xAxis: {
            type: 'category',
            data: dates,
            axisLabel: {
                interval: 0,
                rotate: -40
            }
        },
        yAxis: {
            type: 'value',
        },
        series: series,
        toolbox: {
            show: true,
            x: '80%',
            y: '5',
            feature: {
                magicType: {type: ['bar',]},
                restore: {},
            }
        }
    };
    return option;
}

export function generateProfitChartOption(title, name, dates, data, values) {
    let formatter = null;
    if(values == '原始数据' ||  values == ''){
        // console.log("values",values)
        formatter = function(value) {
            // console.log("value",value)
            return parseFloat(value).toFixed(1) / 100000000 + '亿';
        }
    }
    let option = {
        title: {
            text: title,
            x: 'center',
        },
        tooltip: {
           trigger:'axis'
        },
        toolbox: {
            feature: {
                // dataZoom: {
                //     yAxisIndex: 'none'
                // },
                // restore: {},
                saveAsImage: {
                    title:'',
                    shadowOffsetX: '-30'
                }
            }
        },
        legend: {
            x: '70%',
            y: '5%'
        },
        xAxis: {
            type: 'category',
            data: dates
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: formatter
            },
        },
        series: [{
            name: name,
            type: 'line',
            data: data,
            smooth: true
        }],
    };
    return option;
}

export function generateSecondChartOption(dates, data, up, down) {
    let option = {
        tooltip: {
            trigger: 'axis'
        },
        xAxis: [
            {
                type: 'category',
                data: dates,
                axisLabel: {
                    interval: 0,
                    rotate: -40
                }
            },
            {
                type: 'category',
            },
        ],
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [{
            type: 'line',
            data: data,
            smooth: false,
            markArea: {
                data: [
                    [{
                        name: down,
                        label: {
                            position: 'inside'
                        },
                        emphasis: {
                            label: {
                                position: 'inside'
                            },
                        },
                        itemStyle: {
                            color: "rgba(208, 110, 107, 0.5)"
                        },
                        yAxis: 0
                    }, {
                        yAxis: 1
                    }],
                    [{
                        name: up,
                        label: {
                            position: 'inside'
                        },
                        emphasis: {
                            label: {
                                position: 'inside'
                            },
                        },
                        itemStyle: {
                            color: "rgba(174, 212, 194, 0.5)"
                        },
                        yAxis: 1
                    }, {
                        yAxis: 2
                    }]
                ]
            }
        }],
    };
    return option;
}

export function generateTreeChartOption(title, data) {
    let option = {
        title: {
            text: title,
            x: 'center',
            subtextStyle: {
                align: 'center'
            }, 
        },
        tooltip:{
            formatter: function(params) {
                let prompt = "";
                for(let i=0;i<params.data.info.length;i++){
                    
                    if( params.data.info[i].name== 'PB' || params.data.info[i].name== 'PE'){
                        prompt += params.data.info[i].name + ":" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" ;
                    }else{
                        prompt += params.data.info[i].name + ":" + "&nbsp;&nbsp;&nbsp;";
                    }
                    for(let j=0;j<params.data.info[i].value.length;j++){ 
                        prompt +=" " + params.data.info[i].value[j] + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" ; 
                    }
                    prompt += '<br/>'
                }
                if(params.data.info[0].value.length>1){
                    prompt += "得分数据分别表示'平均值'、'最小值'、'最大值'"
                }
                return prompt;
            },
            
        },
        series: [
            {
                type: 'tree',
                data: [data],
                top: '1%',
                left: '10%',
                bottom: '1%',
                right: '30%',
                symbolSize: (value, params) => {
                    //debugger;
                    if (params.data.class === 1)
                        return 10;
                    return 7;
                },
                label: {
                    normal: {
                        position: 'left',
                        verticalAlign: 'middle',
                        align: 'right',
                        fontSize: 14
                    }
                },
                leaves: {
                    label: {
                        normal: {
                            show: true,
                            position: 'right',
                            verticalAlign: 'middle',
                            align: 'left'
                        }
                    }
                },
                expandAndCollapse: true,
            }
        ]
    };
    return option;
}

export function generateValueChartOption(dates, data,line) {
    let series = [];
    data.map((item)=>{
        series.push({
            name: item.name,
            type: 'line',
            stack: '总量',
            step: 'start',
            areaStyle: {},
            xAxisIndex: 0,
            data: item.data,
        })
        // console.log(series)
    });
    series.push({
        name: line.name,
        type: 'line',
        data: line.data,
        xAxisIndex: 1,
        itemStyle:{
            color:'#000'
        }
    })
    let option = {
        tooltip: {},
        xAxis: [
            {
                type: 'category',
                data: dates,
                axisLabel: {
                    interval: 0,
                    rotate: -40
                }
            },
            {
                type: 'category',
            }
        ],
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: function(value, index) {
                    return parseFloat(value).toFixed(1) / 100000000 + '亿';
                }
            }
        },
        series: series,
        legend:{}
    };
    return option;
}


export function generateMScoreChartOption(title, header, data) {
    let option = {
        tooltip:{
            trigger: 'axis'
        },
        title: {
            text: title,
            x: 'center',
        },
        xAxis: {
            type: 'category',
            data: header,
            axisLabel: {
                interval: 0,
                rotate: -40
            }
        },
        yAxis: [
            {
                type: 'value'
            }
        ],
        series: [{
            data: data,
            type: 'line',
        }]
    };
    return option;
}

// 柱状图 媒体来源占比图
export function getLeftDarChart(xd, yd) {

    let option = {
        color: ['#d1a97b'],
        tooltip: {
            trigger: 'axis',
            axisPointer: { // 坐标轴指示器，坐标轴触发有效
                type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            height: '90%',
            containLabel: true
        },
        xAxis: [{
            type: 'category',
            data: xd,
            axisTick: {
                alignWithLabel: true
            },
            axisLabel: {
                interval: 0,
                // rotate: 30,
                margin: 15,
            }
        }],
        yAxis: [{
            type: 'value'
        }],
        series: [{
            name: '直接访问',
            type: 'bar',
            barWidth: '20%',
            data: yd
        }]
    }

    return option;
}


// 仪表盘 情感分布图
export function getGaugeChart() {
    let option = {
        color: ['#2de5f0', '#ffd200', '#61a0a8'],
        grid: {
            left: '5%',
            right: '5%',
            height: '100%',
        },
        series: [{
            name: '敏感度',
            type: 'gauge',
            detail: {
                formatter: '{value}%',
                fontSize: 24,
                fontWeight: 'bold',
                offsetCenter: [0, '70%'],
            },
            axisLine: {
                show: true,
                length: 5,
                lineStyle: {
                    width: 10,
                    shadowBlur: 0,
                    color: [
                        [0.3, '#67e0e3'],
                        [0.7, '#37a2da'],
                        [1, '#fd666d']
                    ]
                }
            },
            splitLine: {
                show: true,
                length: '15',
                lineStyle: {
                    color: '#fff'
                }
            },
            data: [{
                value: 36,
                name: '敏感度',
            }]

        }]
    }

    // app.timeTicket = setInterval(function() {
    //     option.series[0].data[0].value = (Math.random() * 100).toFixed(2) - 0;
    //     GaugeChart.setOption(option, true);
    // }, 2000);

    return option;
}


//舆情分析页 饼状图
export function getFXPiachart(title, datas) {

    let option = {
        color: ['#78b3f9', '#68c9cb', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'],
        title: {
            text: '敏感度',
            left: 'center',
            top: '50%',
            padding: [24, 0],
            textStyle: {
                color: '#d48265',
                fontSize: 16,
                align: 'center'
            }
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        // legend: {
        //     orient: 'vertical',
        //     x: 'right',
        //     bottom: '10%',
        //     data: ['微博', '论坛', '博客', '视频', '网站']
        // },
        legend: {
            selectedMode: false,
            formatter: function(name) {
                var total = 0; //各科正确率总和
                datas.forEach(function(value) {
                    total += value.value;
                });
                return ((datas[0].value / total) * 100).toFixed(2) + "%";
            },
            data: [datas[0].name],
            // data: ['高等教育学'],
            // itemGap: 50,
            left: 'center',
            top: 'center',
            icon: 'none',
            align: 'center',
            textStyle: {
                color: "#d48265",
                fontSize: 32
            },
        },
        grid: {
            height: '80%',
            y: '-5%',
        },
        // toolbox: {
        //     show: true,
        //     feature: {
        //         // mark: { show: true },
        //         // dataView: { show: true, readOnly: false },
        //         magicType: {
        //             show: true,
        //             type: ['pie', 'funnel'],
        //             option: {
        //                 funnel: {
        //                     x: '25%',
        //                     width: '50%',
        //                     funnelAlign: 'center',
        //                     max: 1548
        //                 }
        //             }
        //         },
        //         restore: { show: true },
        //         saveAsImage: { show: true }
        //     }
        // },
        calculable: true,
        series: [{
            name: '访问来源',
            type: 'pie',
            radius: ['50%', '70%'],
            itemStyle: {
                normal: {
                    label: {
                        show: true,
                        formatter: "{b}({d}%)",
                        fontSize: 16,
                        fontWeight: 'bold',
                    },
                    labelLine: {
                        show: true
                    }
                },
                emphasis: {
                    label: {
                        show: true,
                        position: 'center',
                        textStyle: {
                            fontSize: '24',
                            fontWeight: 'bold'
                        }
                    }
                }
            },
            data: datas
                // [
                //     { value: 335, name: '微博' },
                //     { value: 310, name: '论坛' },
                //     { value: 234, name: '博客' },
                //     { value: 135, name: '视频' },
                //     { value: 1548, name: '网站' }
                // ]
        }]
    }
    return option;
}

// 地域分析 中国地图
export function getMapChart(title, data) {
    // function randomData() {
    //     return Math.round(Math.random() * 1000);
    // }

    let option = {
        color: ['#2FC25B'],
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data: ['iphone3']
        },
        visualMap: {
            min: 0,
            max: 1000000,
            color: ['#3661a3', '#579ff8', '#75b3f9', '#90c8fa', '#cbe9fd'],
            left: 'left',
            top: 'bottom',
            text: ['高', '低'], // 文本，默认为数值文本
            calculable: true
        },
        // toolbox: {
        //     show: true,
        //     orient: 'vertical',
        //     left: 'right',
        //     top: 'center',
        //     feature: {
        //         dataView: { readOnly: false },
        //         restore: {},
        //         saveAsImage: {}
        //     }
        // },
        series: [{
            name: '',
            type: 'map',
            mapType: 'china',
            roam: false,
            label: {
                normal: {
                    show: true
                },
                emphasis: {
                    show: true
                }
            },
            data: data
        }]
    }

    return option;
}

//关键词云
// option.series[0].data = JosnList;
function getArrItem(arr, num) {
    var temp_array = new Array();
    for (var index in arr) {
        temp_array.push(arr[index]);
    }
    var return_array = new Array();
    for (var i = 0; i < num; i++) {
        if (temp_array.length > 0) {
            var arrIndex = Math.floor(Math.random() * temp_array.length);
            return_array[i] = temp_array[arrIndex];
            temp_array.splice(arrIndex, 1);
        } else {
            break;
        }
    }
    return return_array;
}
export function getKeyWorkCloudChart(title, JsonList) {
    const color = [
        [24,144,255],
        [47,194,91],
        [65,217,199],
        [250,204,20],
        [97,160,168],
        [212,130,101],
        [145,199,174],
        [116,159,131],
        [202,134,34],
        [189,162,154],
        [110,112,116],
        [84,101,112],
        [196,204,211]
    ];
    let option = {
        // color: ['#1890FF', '#2FC25B', '#41D9C7', '#FACC14', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'],  
        // tooltip: {
        //     show: true
        // },
        gird: {
            width: '100%',
            height: '100%',
        },
        // toolbox: {
        //     feature: {
        //         saveAsImage: {
        //             iconStyle: {
        //                 normal: {
        //                     color: '#FFFFFF'
        //                 }
        //             }
        //         }
        //     }
        // },
        series: [{
            name: '热点分析',
            type: 'wordCloud',
            // size: ['9%', '99%'],
            // sizeRange: [12, 30],
            // textRotation: [0, 45, 90, -45],
            gridSize: 20,
            sizeRange: [12, 50],
            rotationRange: [0, 0],
            // shape: 'circle',
            textPadding: 0,
            autoSize: {
                enable: true,
                // minSize: 12
            },
            textStyle: {
                normal: {
                    color:function() {
                        let arr_color = getArrItem(color,1);

                        return 'rgb(' + [
                            arr_color[0][0],
                            arr_color[0][1],
                            arr_color[0][2],
                            // Math.round(Math.random() * 250),
                            // Math.round(Math.random() * 250),
                            // Math.round(Math.random() * 250)
                        ].join(',') + ')';
                    }
                },
                emphasis: {
                    shadowBlur: 3,
                    shadowColor: '#f1f1f1'
                }
            },
            data: JsonList
        }]
    }

    // keywordChart.on('click', function(params) {
    //     alert('搜索关键词' + (params.name));
    //     // window.open('https://www.baidu.com/s?wd=' + encodeURIComponent(params.name));
    // });

    return option;
}


//融资融券
export function getRROption(title, Datas, Dates, Per) {
    let option = {
        color: ['#1890FF', '#2FC25B', '#88b3f5', '#ffd200', '#c4ccd3'],
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['警戒线指数', '融资余额(元)']
        },
        grid: {
            y: '10%',
            height: '70%',
            bottom: 0,
        },
        xAxis: [
            {
                type: 'category',
                data: Dates,
                axisPointer: {
                    type: 'shadow'
                }
            }
        ],
        yAxis: [
            {
                type: 'value',
                name: '融资余额(元)',
                axisLabel: {
                    formatter: function(value,index){
                        let v = value / 100000000;
                        return (v + "亿")
                        
                    }
                }
            },
            {
                type: 'value',
                name: '警戒线指数',
                min:0,
                max:100,
                axisLabel: {
                    formatter: '{value} %'
                }
            }
        ],
        series: [
            {
                name:'融资余额(元)',
                type:'line',
                data:Datas
            },
            {
                name:'警戒线指数',
                type:'line',
                yAxisIndex: 1,
                data:Per
            }
        ]
    }
    return option;
}

//融资融券
export function getRLOption(title, Datas, Dates, Per) {
    let option = {
        color: ['#1890FF', '#2FC25B', '#88b3f5', '#ffd200', '#c4ccd3'],
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['融资余量(股)']
        },
        grid: {
            y: '10%',
            height: '70%',
            bottom: 0,
        },
        xAxis: [
            {
                type: 'category',
                data: Dates,
                axisPointer: {
                    type: 'shadow'
                }
            }
        ],
        yAxis: [
            {
                type: 'value',
                name: '融资余量(股)',
                axisLabel: {
                    formatter: '{value} 股'
                }
            }
            // {
            //     type: 'value',
            //     name: '警戒线指数',
            //     min:0,
            //     max:100,
            //     axisLabel: {
            //         formatter: '{value} %'
            //     }
            // }
        ],
        series: [
            {
                name:'融资余量(股)',
                type:'line',
                data:Datas
            }
        ]
    }
    return option;
}

// 监管风险-行业监管处罚TOP5
export function getSVTop5BarOption(xData, yData) {
  const option = {
      color: ['#E0A86E'],
      tooltip: {
          trigger: 'axis'
      },
      grid: {
        top: 5,
        left: 0,
        right: 0,
        bottom: 0,
        containLabel: true
      },
      xAxis: [{
          type: 'category',
          data: ['区域监管函', '监管措施', '纪律处分', '行政处罚', '立案调查'],
          axisLabel: {
              interval: 0,
              rotate: 0,
              fontSize: 12,
          }
      }],
      yAxis: [{
          type: 'value'
      }],
      series: [{
              name: '行业监管处罚TOP5(本年度)',
              type: 'bar',
              barWidth: '60%',
              data: yData,
          }
      ]
  }
  return option;
}

// 行业监管处罚类型分布
export function getSVTypeBarOption(legends, xData, yData) {
  if(!legends) {
    legends = [];
  }
  // let legends = ['监管函', '监管措施', '纪律处分', '行政处罚', '立案调查', '市场禁入'];
  let legendData =  legends.map((item, index) => {
    return { 
      name: item,
      icon: 'circle'
    }
  });
  let barArr = legends.map((item, index)=>{
    return {
        name: item,
        type: 'bar',
        barWidth: '60%',
        stack: '处罚',
        data: yData[index]
    }
  });
  let lineArr = legends.map((item, index)=>{
    return {
        name: item,
        type: 'line',
        stack: '处罚曲线',
        data: yData[index]
    }
  });
  let option = {
      color: ['#D89F61', '#B06049', '#E8B256', '#998246', '#D28249', '#79604B'],
      tooltip: {
          trigger: 'axis'
      },
      grid: {
        left: 0,
        right: 0,
        bottom: 0,
        containLabel: true
      },
      legend: {
          itemWidth: 6,
          itemHeight:6,
          textStyle: {
            fontSize: 12
          },
          data: legendData
      },
      xAxis: [{
          type: 'category',
          data: xData,
          axisLabel: {
              interval: 0,
              rotate: 0,
              fontSize: 12,
          }
      }],
      yAxis: [{
          type: 'value'
      }],
      series: barArr.concat(lineArr)
      // [
      //     {
      //         name: '监管函',
      //         type: 'bar',
      //         barWidth: '35px',
      //         stack: '处罚',
      //         data: yData[0],
      //     },
      //     {
      //       name: '监管函',
      //       type: 'line',
      //       data: yData[0],
      //     },
      // ]
  }
  return option;
}

// 两融警戒提示
export function getBalanceOption(title, Datas, Dates) {
  //'#FBF0E6'
    let option = {
        color: ['#D99F62'],
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: ['融资余额(元)']
        },
        grid: {
            y: '10%',
            height: '70%',
            bottom: 0,
        },
        xAxis: [
            {
                type: 'category',
                data: Dates,
                axisPointer: {
                    type: 'shadow'
                }
            }
        ],
        yAxis: [
            {
                type: 'value',
                name: '融资余额(元)',
                axisLabel: {
                    formatter: function(value,index){
                        let v = value / 100000000;
                        return (v + "亿")
                        
                    }
                }
            },
        ],
        series: [
            {
                name:'融资余额(元)',
                type:'line',
                data:Datas,
                areaStyle: {
                  color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                      offset: 0,
                      color: '#FBF0E6'
                  }, {
                      offset: 1,
                      color: '#fff'
                  }])
              },
            }
        ]
    }
    return option;
}

export function getStockholderOption(num){
  num = parseFloat(num);
  return {
    color: ['#CC5C3D', '#E1E6EC'],
    // tooltip: {
    //    show: true,
    //     trigger: 'item',
    //     formatter: function(params, ticket, callback){
    //       const num = '20000';
    //       const str = `<div style="text-align:center;line-height:22px;">
    //         <div style="font-size: 14px;
    //         font-weight: 400;
    //         color: rgba(0,0,0,0.45);">占总股本</div>
    //         <div style="font-size:30px">${params.percent}%</div>
    //       </div>`;
    //       return str;
    //     },
    //     position:function(point, params, dom, rect, size) {
    //       const marginW = Math.ceil(size.contentSize[0]/2);
    //       const marginH = Math.ceil(size.contentSize[1]/2);
    //       dom.style.marginLeft='-'+ marginW+'px';
    //       dom.style.marginTop='-'+ marginH+'px';
    //       return ['50%', '50%']
    //     },
    //     alwaysShowContent: true,
    //     backgroundColor: '#fff',
    //     textStyle:{
    //       color: '#333'
    //     }
        
    //     //"{a} <br/>{b}: {c} ({d}%)"
    // },
    legend: {
      selectedMode: false,
        orient: 'vertical',
        formatter: function(name) {
          return  ((num) * 100).toFixed(2) + "%";
        },
        data:['质押股权'],
        left: 'center',
        top: 'center',
        icon: 'none',
        align: 'center',
        textStyle: {
            color: "#000",
            fontSize: 30
        },
    },
    series: [
        {
            name:'第一股东股权质押风险提示',
            type:'pie',
            radius: ['40%', '60%'],
            //center : ['80', '50%'],
            avoidLabelOverlap: false,
            label: {
                normal: {
                    show: true,
                    formatter: `{b}:\r\n{d}%`
                    //position: 'center'
                },
                emphasis: {
                    show: true,
                    // textStyle: {
                    //     fontSize: '30',
                    //     fontWeight: 'bold'
                    // }
                }
            },
            labelLine: {
                normal: {
                    show: true
                }
            },
            data:[
                {value:num, name:'质押股权'},
                {value:(1-num), name:'其它'},
            ]
        }
    ]
};
}